package com.qyhl.module_home.city.bestone.ontype;


import com.qyhl.module_home.app.HomeApplication;
import com.qyhl.module_home.common.HomeUrl;
import com.qyhl.webtv.basiclib.utils.NetUtil;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.entity.home.BestoneItemTypeBean;

import java.util.List;

public class BestoneTypeModel implements BestoneTypeContract.BestoneTypeModel {
    private BestoneTypeContract.BestoneTypePresenter presenter;

    public BestoneTypeModel(BestoneTypeContract.BestoneTypePresenter presenter) {
        this.presenter = presenter;
    }

    @Override
    public void getData(String typeId) {
        if (NetUtil.isNetworkAvalible(HomeApplication.getApp())) {

            EasyHttp.get(HomeUrl.GET_BESTONE_TYPELIST)
                    .params("typeId", typeId)
                    .execute(new SimpleCallBack<List<BestoneItemTypeBean>>() {
                        @Override
                        public void onError(ApiException e) {
                            presenter.getDataError("网络繁忙，请稍后再试");
                        }

                        @Override
                        public void onSuccess(List<BestoneItemTypeBean> bestoneItemTypeBeans) {
                            presenter.getDataSuccess(bestoneItemTypeBeans);
                        }
                    });

        } else {
            presenter.getDataError("无网络连接，请检查您的网络...");
        }
    }
}
